package com.tanhua.server.controller;

import com.tanhua.server.service.BaiDuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/baidu")
public class BaiDuController {

    @Autowired
    private BaiDuService baiDuService;

    /**
     * 上报地理位置
     * POST     /location
     * latitude  纬度
     * longitude  经度
     * addrStr 位置描述
     * 返回值空d
     */
    @PostMapping("/location")
    public ResponseEntity location(@RequestBody Map map) {
        //获取请求参数
        String str1 = map.get("latitude").toString();
        Double lat = Double.valueOf(str1);
        String str2 = map.get("longitude").toString();
        Double lon = Double.valueOf(str2);
        String addrStr = map.get("addrStr").toString();
        baiDuService.location(lat, lon, addrStr);
        return ResponseEntity.ok(null);
    }
}
